package cn.dubito.miaosha.dao;

import cn.dubito.miaosha.domain.OrderInfo;
import cn.dubito.miaosha.domain.SeckillOrder;
import org.apache.ibatis.annotations.*;

/**
 * @author liliang
 * @description:
 * @date 2018/3/31.
 */
@Mapper
public interface OrderDao {

    /**
     * 获取秒杀订单
     *
     * @param userId
     * @param goodsId
     * @return
     */
    @Select("select * from seckill_order where user_id = #{userId} and goods_id = #{goodsId}")
    SeckillOrder getSeckillOrderByUserIdAndGoodsId(@Param("userId") long userId, @Param("goodsId") long goodsId);

    /**
     * 添加订单信息
     *
     * @param orderInfo
     * @return
     */
    @Insert("INSERT INTO order_info(user_id, goods_id, delivery_addr_id, goods_name, goods_count, goods_price, order_channel, status, create_date) values(#{userId}, #{goodsId}, #{deliveryAddrId}, #{goodsName}, #{goodsCount}, #{goodsPrice}, #{orderChannel}, #{status}, #{createDate})")
    @SelectKey(keyColumn = "id", keyProperty = "id", resultType = long.class, before = false, statement = "select last_insert_id()")
    long insert(OrderInfo orderInfo);

    /**
     * 添加秒杀订单信息
     *
     * @param seckillOrder
     * @return
     */
    @Insert("insert into seckill_order(user_id,goods_id,order_id) values(#{userId},#{goodsId},#{orderId})")
    int insertSeckillOrder(SeckillOrder seckillOrder);

    /**
     * 获取订单信息
     *
     * @param orderId
     * @return
     */
    @Select("select * from order_info where id = #{orderId}")
    OrderInfo getOrderById(@Param("orderId") long orderId);
}
